<?php

namespace app\admin\controller;

use think\Controller;

class Index extends Base
{
    public function index()
    {
        //首先获取到用户的session_id
        $role_id = $this->getLoginUser()->role_id;
        try {
            //根据用户id获取到其拥有的权限信息
            $ps_ids = model('role')->get(['role_id' => $role_id]);
            $ps_ids = explode(',', $ps_ids->ps_ids);
            $permission_A = model('permission')->where('ps_level', '0')->whereIn('ps_id', $ps_ids)->select();
            $permission_B = model('permission')->where('ps_level', '1')->whereIn('ps_id', $ps_ids)->select();
        } catch (\Exception $e) {
            if ($this->getLoginUser()->mg_id == 1) {
                $permission_A = model('permission')->where('ps_level', '0')->select();
                $permission_B = model('permission')->where('ps_level', '1')->select();
            } else {
                $permission_A = [];
                $permission_B = [];
            }
        }
        //查询并显示首页信息
        return $this->fetch('', ['permission_A' => $permission_A, 'permission_B' => $permission_B]);
    }

    public function welcome()
    {
        return $this->fetch();
    }

    public function test()
    {

    }

    public function map($data)
    {
        return json_encode(\Map::staticimage($data));
    }
}
